<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>{$meta_title}-狂雨小说CMS</title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
        <link rel="stylesheet" href="__ADMIN__/css/admin.css">
    </head>
    <body>
    <div class="layui-fluid">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md12">
                <form class="layui-form" action="{:url('renew')}">
                    <div class="layui-card">
                        <div class="layui-card-body">
                            <div style="padding-bottom: 10px;">
                                <blockquote class="layui-elem-quote layui-quote-nm">
                                    <p>狂雨小说采集系统，有点击才去检查，无点击不会自动更新，对于新站几乎很少会触发更新小说。</p>
                                    <p>因此，我写了这个自动更新采集章节的扩展，暂时未采用插件的形式，看情况再说要不要转成插件。</p>
                                    <p class="tip">注意：听官方的话，已经采集数据的采集规则请不要删除否则无法自动更新</p>
                                    </br>
                                </blockquote>
                                <div class="layui-container">
                                    <div class="layui-row layui-col-space15">
                                        <div class="layui-col-md6">
                                            <div class="layui-progress layui-progress-big" lay-filter="renew_process" lay-showPercent="yes">
                                                <div class="layui-progress-bar layui-bg-cyan" lay-percent="0%"></div>
                                            </div>
                                            <div>
                                                <p id="mission_detail">
                                                    <span class="layui-badge-dot"></span>正在检测后台是否有任务执行，请稍等……
                                                </p>
                                                <p id="mission_status">
                                                </p>


                                            </div>
                                        </div>
                                        <div class="layui-col-md4 layui-col-md-offset1">
                                            <button class="layui-btn layui-btn-warm" lay-submit lay-filter="all_renew" type="submit"><i class="layui-icon layui-icon-refresh-3"></i>全量更新</button>
                                            <button class="layui-btn layui-btn-normal" type="button" onclick="admin_show('手动更新','{:url('renew')}',0,0,1)"><i class="layui-icon layui-icon-refresh"></i>手动更新</button>
                                            <button class="layui-btn layui-btn-danger" type="button" onclick="admin_del(this,'{:url('del')}?renew_time=all')"><i class="layui-icon layui-icon-delete"></i>清空日志</button>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <table class="layui-table">
                                <colgroup>
                                    <col width="160">
                                    <col width="160">
                                    <col width="120">
                                    <col width="80">
                                    <col width="100">
                                    <col width="100">
                                    <col width="100">
                                    <col width="100">
                                    <col width="100">
                                    <col width="200">
                                </colgroup>
                                <thead>
                                    <tr>
                                        <th>开始时间</th>
                                        <th>完成时间</th>
                                        <th>耗时</th>
                                        <th>总页数</th>
                                        <th>出错页数</th>
                                        <th>数据总量</th>
                                        <th>更新总量</th>
                                        <th>错误数量</th>
                                        <th>更新类型</th>
                                        <th><div align="center">操作</div></th>
                                    </tr>
                                </thead>
                                <tbody>
                                    {notempty name="list"}
                                    {volist name="list" id="vo"}
                                    <tr>
                                        <td>{$vo.renew_time|time_format="Y-m-d H:i:s"}</td>
                                        <td>{$vo.finish_time|time_format="Y-m-d H:i:s"}</td>
                                        <td>{$vo.total_time|default=""}</td>
                                        <td>{$vo.total_page|default=""}</td>
                                        <td>{$vo.error_page|default=""}</td>
                                        <td>{$vo.total_num|default=""}</td>
                                        <td>{$vo.renew_num|default=""}</td>
                                        <td>{$vo.error_num|default=""}</td>
                                        <td>{$vo.type_text|default="未定义"}</td>
                                        <td align="center">
                                            <a onclick="admin_show('查看日志','{:url('records')}?renew_time={$vo.renew_time}',0,0,1)" class="layui-btn layui-btn-normal layui-btn-xs" href="javascript:;"><i class="layui-icon layui-icon-tips"></i>查看日志</a>
                                            <a class="layui-btn layui-btn-danger layui-btn-xs" onclick="admin_del(this,'{:url('del')}?renew_time={$vo.renew_time}')"><i class="layui-icon layui-icon-delete"></i>删除日志</a>
                                        </td>
                                    </tr>
                                    {/volist}
                                    {else/}
                                        <td colspan="12"> aOh! 暂时还没有内容! </td>
                                    {/notempty}
                                </tbody>
                            </table>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
    <script type="text/javascript" src="__STATIC__/jquery/jquery.min.js"></script>
    <script type="text/javascript" src="__ADMIN__/lib/layui/layui.js"></script>
    <script type="text/javascript" src="__ADMIN__/js/admin.js"></script>
    <script type="text/javascript">
        layui.use('form', function(){
            let form = layui.form;
            form.on('submit(all_renew)', function(data){
                layer.confirm('确认要执行全量更新吗？',function(index){
                    $.get($(data.form).attr('action'),data.field, function(data){
                        if(data.code){
                            layer.msg(data.msg, {icon: 1,shade: 0.3,time: 2000},function(layero, index){
                                location.reload();
                            });
                        } else {
                            layer.msg(data.msg, {icon: 0});
                        }
                    }, "json");
                });
                return false;
            });
        });
        layui.use('element', function(){
            let $ = layui.$,element = layui.element; //Tab的切换功能，切换事件监听等，需要依赖element模块
            //loading
            let n = 0;
            let timer = setInterval(function(){

                $.ajax({
                    url:'{:url("get_processing")}',
                    type:'post',
                    data:{},
                    // beforeSend:function () {
                    //     this.layerIndex = layer.load(0, { shade: [0.5, '#393D49'] });
                    // },
                    success:function(res){
                        let code = res.code;
                        let data = res.data;
                        let title = res.msg;
                        if(code && data){
                            let all = data.all_novel;
                            let now = data.now_novel;
                            let novel = data.novel;
                            $("#mission_detail").html('<span class="layui-badge-dot layui-bg-green"></span> '+ title +' | 书名：[' + novel.title + '] 编号：' + novel.id );
                            $("#mission_status").html('<span class="layui-badge-dot layui-bg-green"></span> 状态：' + novel.status);
                            n = Math.floor(now/all*100);
                            if(n > 100){
                                n = 100;
                                clearInterval(timer);
                            }
                        }else{
                            $("#mission_detail").html('<span class="layui-badge-dot layui-bg-black"></span> '+ title);
                            $("#mission_status").text('');
                            n = 100;
                            element.progress('renew_process', n+'%');
                            clearInterval(timer);
                        }
                    },
                });

                element.progress('renew_process', n+'%');
            }, 3000);

        });
    </script>
    </body>
</html>